import { Module } from '@nestjs/common';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';

import { MysqlModule } from './database/mysql/mysql.module';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserController } from './module/user/user.controller';
import { UserModule } from './module/user/user.module';
import { AuthModule } from './module/auth/auth.module';
import * as path from 'path';
import { CustomExceptionFilter } from './common-middleware/filter/exception.filter';
import { ValidationPipe } from './common-middleware/pipe/validate.pipe';
// import { RequestInterceptor } from './common-middleware/interceptor/request.interceptor';
import { ResponseInterceptor } from './common-middleware/interceptor/response.interceptor';
import { JwtAuthGuard } from './common-middleware/guard/jwt-auth.guard';

@Module({
  imports: [
    ConfigModule.forRoot({ envFilePath: path.resolve(__dirname, '../.env') }),
    MysqlModule,
    UserModule,
    AuthModule,
  ],
  controllers: [AppController, UserController],
  providers: [
    AppService,
    { provide: APP_FILTER, useClass: CustomExceptionFilter }, // 过滤器 - 全局异常过滤器
    { provide: APP_PIPE, useClass: ValidationPipe }, // 管道 - http入参参数校验管道
    // { provide: APP_INTERCEPTOR, useClass: RequestInterceptor }, // 拦截器 - 入参参数转换拦截器
    { provide: APP_INTERCEPTOR, useClass: ResponseInterceptor }, // 拦截器 - 响应参数转换拦截器
    { provide: APP_GUARD, useClass: JwtAuthGuard }, // 守卫 - jwt验证守卫
  ],
})
export class AppModule {}
